package centerberg.game;

import java.awt.Shape;

import centerberg.engine.Drawable;
import centerberg.engine.Engine;
import centerberg.engine.PhysicsObject;
import centerberg.engine.RigidBody;
import centerberg.engine.Texture;
import centerberg.engine.Vector;

public class Ball extends RigidBody implements Drawable{
    Texture texture;
    private boolean delete;
    private int duration = DEFAULT_DURATION;
    public static final int DEFAULT_DURATION = 16000;
    private long spawnTime;
    public Ball(Shape shape,Texture texture, double mass) {
        super(shape);
        spawnTime = System.currentTimeMillis();
        this.texture = texture;
        setMass(mass);
        setBounciness(0.8);
        delete = false;
    }
    @Override
    public Texture getTexture() {
        return texture;
    }
    
    @Override
    public void translated(double dx, double dy) {
        texture.translate(dx, dy);
    }
    @Override
    public void collided(PhysicsObject other) {
        if(other instanceof Player) {
            delete = true;
        }
    }
    @Override
    public void tick(double elapsed) {
        if(delete || duration < System.currentTimeMillis() - spawnTime)  {
            Engine.getInstance().physics.removeFromWorld(this);
            Engine.getInstance().remove(this);
        }   
    }
}
